// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   ChangePasswordDialog.java

package com.boci.clientapp.authentication;

import com.boci.clientapp.authentication.action.ChangePasswordAction;
import com.boci.clientapp.main.*;
import com.boci.common.ui.AbstractDialog;
import com.boci.common.util.MessagesConfigurator;
import com.boci.common.util.PerformanceLogger;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.*;
import javax.swing.*;

public class ChangePasswordDialog extends AbstractDialog
{

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        MessagesConfigurator msgConfigurator = ClientAppLoader.getMessagesConfigurator();
        lblNotes1.setText(msgConfigurator.getUIMessages("CHANGE_PASS.NOTE1", pLocale));
        lblNotes2.setText(msgConfigurator.getUIMessages("CHANGE_PASS.NOTE2", pLocale));
        lblCurPasswd.setText(msgConfigurator.getUIMessages("CHANGE_PASS.CURR_PASSWD", pLocale));
        lblNewPasswd.setText(msgConfigurator.getUIMessages("CHANGE_PASS.NEW_PASSWD", pLocale));
        lblReEnterPasswd.setText(msgConfigurator.getUIMessages("CHANGE_PASS.RE_ENTER_PASSWD", pLocale));
        btnChgPasswd.setText(msgConfigurator.getUIMessages("CHANGE_PASS.SUBMIT", pLocale));
        btnCancel.setText(msgConfigurator.getUIMessages("CHANGE_PASS.CANCEL", pLocale));
        setTitle(msgConfigurator.getUIMessages("CHANGE_PASS.TITLE", pLocale));
    }

    private void setFont(Locale pLocale)
    {
        lblNotes1.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNotes2.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblCurPasswd.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblNewPasswd.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        lblReEnterPasswd.setFont(ClientAppLoader.getLargeBoldTextFont(pLocale));
        btnChgPasswd.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        btnCancel.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        lblNewPasswd.setHorizontalAlignment(4);
        lblCurPasswd.setHorizontalAlignment(4);
        lblReEnterPasswd.setHorizontalAlignment(4);
    }

    public ChangePasswordDialog(TradingClientApp owner, boolean modal, Locale pLocale)
    {
        super(owner, modal, pLocale, true);
        rootPanel = new JPanel();
        lblNotes1 = new JLabel();
        lblNotes2 = new JLabel();
        lblCurPasswd = new JLabel();
        lblNewPasswd = new JLabel();
        lblReEnterPasswd = new JLabel();
        pwdCurPasswd = new JPasswordField();
        pwdNewPasswd = new JPasswordField();
        pwdReEnterPasswd = new JPasswordField();
        btnChgPasswd = new JButton();
        btnCancel = new JButton();
        initGUI(pLocale);
    }

    public void initGUI(Locale pLocale)
    {
        setSize(440, 215);
        rootPanel.setLayout(null);
        rootPanel.setBackground(Color.WHITE);
        getContentPane().setLayout(new BorderLayout());
        getContentPane().add(rootPanel, "Center");
        lblNotes1.setBounds(25, 1, 382, 20);
        lblNotes2.setBounds(25, 15, 349, 20);
        lblCurPasswd.setBounds(5, 40, 220, 20);
        lblNewPasswd.setBounds(5, 65, 220, 20);
        lblReEnterPasswd.setBounds(5, 90, 220, 20);
        pwdCurPasswd.setBounds(230, 40, 180, 20);
        pwdNewPasswd.setBounds(230, 65, 180, 20);
        pwdReEnterPasswd.setBounds(230, 90, 180, 20);
        btnChgPasswd.setBounds(70, 120, 150, 25);
        btnCancel.setBounds(250, 120, 120, 25);
        rootPanel.add(lblNotes2);
        rootPanel.add(lblNotes1);
        rootPanel.add(lblCurPasswd);
        rootPanel.add(lblNewPasswd);
        rootPanel.add(lblReEnterPasswd);
        rootPanel.add(pwdCurPasswd);
        rootPanel.add(pwdNewPasswd);
        rootPanel.add(pwdReEnterPasswd);
        rootPanel.add(btnChgPasswd);
        rootPanel.add(btnCancel);
        btnChgPasswd.setActionCommand("CHANGE_PASSWORD_ACTION");
        btnCancel.setActionCommand("CANCEL_ACTION");
        btnChgPasswd.addActionListener(this);
        btnCancel.addActionListener(this);
        setText(pLocale);
    }

    public HashMap getInputValue(String pActionType)
    {
        HashMap inpValMap = new HashMap();
        String strCurPass = String.copyValueOf(pwdCurPasswd.getPassword());
        String strNewPass = String.copyValueOf(pwdNewPasswd.getPassword());
        String strConfPass = String.copyValueOf(pwdReEnterPasswd.getPassword());
        inpValMap.put("password", strCurPass);
        inpValMap.put("newPassword", strNewPass);
        inpValMap.put("retypePassword", strConfPass);
        return inpValMap;
    }

    public void actionPerformed(ActionEvent e)
    {
        if(validate(e.getActionCommand()))
        {
            PerformanceLogger.startAppTimer();
            String strActionType = e.getActionCommand();
            ChangePasswordAction chgPassAct = new ChangePasswordAction();
            chgPassAct.doProcess(getInputValue(strActionType), strActionType);
            PerformanceLogger.stopAppTimer();
            PerformanceLogger.doLog((new StringBuilder()).append("CHANGE_PASSWORD_DIALOG.").append(strActionType).toString());
        }
    }

    public void refresh(ResponseVO pResponseVO)
    {
        pwdCurPasswd.setText("");
        pwdNewPasswd.setText("");
        pwdReEnterPasswd.setText("");
        setDefFocus();
    }

    private boolean validate(String pActionType)
    {
        if(pActionType.equals("CANCEL_ACTION"))
            return true;
        boolean validFlag = true;
        String strCurPasswd = String.copyValueOf(pwdCurPasswd.getPassword());
        String strNewPasswd = String.copyValueOf(pwdNewPasswd.getPassword());
        String strReEnterPasswd = String.copyValueOf(pwdReEnterPasswd.getPassword());
        ArrayList msgKeyList = new ArrayList();
        if(strCurPasswd == null || strCurPasswd.length() == 0)
        {
            msgKeyList.add("CHGPASS.MISSING_CUR_PASSWD");
            validFlag = false;
        }
        if(strNewPasswd == null || strNewPasswd.length() == 0)
        {
            msgKeyList.add("CHGPASS.MISSING_NEW_PASSWD");
            validFlag = false;
        }
        if(strReEnterPasswd == null || strReEnterPasswd.length() == 0)
        {
            msgKeyList.add("CHGPASS.MISSING_CONF_PASSWD");
            validFlag = false;
        }
        if(strNewPasswd != null && strReEnterPasswd != null && !strNewPasswd.equals(strReEnterPasswd))
        {
            msgKeyList.add("CHGPASS.PASSWD_NOTMATCH");
            validFlag = false;
        }
        if(!validFlag)
        {
            ApplicationService.getInstance().showWarningDialog(null, msgKeyList);
            return false;
        } else
        {
            return true;
        }
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                pwdCurPasswd.requestFocus();
            }

        }
);
    }

    private JPanel rootPanel;
    private JLabel lblNotes1;
    private JLabel lblNotes2;
    private JLabel lblCurPasswd;
    private JLabel lblNewPasswd;
    private JLabel lblReEnterPasswd;
    private JPasswordField pwdCurPasswd;
    private JPasswordField pwdNewPasswd;
    private JPasswordField pwdReEnterPasswd;
    private JButton btnChgPasswd;
    private JButton btnCancel;

}
